<template>
    <div class="page-wrapper">
        <!-- 头部信息 -->
        <header>
            <div class="filter-part">
                <div class="filter-item">
                    <Input
                        v-model="filterObj.orderNumber"
                        placeholder="订单编号"
                        clearable
                    />
                </div>
                <div class="filter-item">
                    <DatePicker
                        type="daterange"
                        v-model="filterObj.time"
                        placement="bottom-end"
                        placeholder="请选择申请日期"
                        separator="至"
                        style="width: 200px"
                    ></DatePicker>
                </div>
                <div class="filter-item">
                    <Input
                        v-model="filterObj.memberName"
                        placeholder="客户名"
                        clearable
                    />
                </div>
                <div class="filter-item">
                    <Input
                        v-model="filterObj.memberTelephone"
                        placeholder="手机号"
                        clearable
                    />
                </div>
                <div class="filter-item">
                    <Select
                        v-model="filterObj.businessSources"
                        :key="filterObj"
                        filterable
                        placeholder="订单类型"
                        clearable
                    >
                        <Option value="all" key="all">全部</Option>
                        <Option
                            v-for="item in businessSourcesList"
                            :value="item.dictValue"
                            :key="item.dictValue"
                            >{{ item.dictName }}</Option
                        >
                    </Select>
                </div>
                <div class="filter-item">
                    <Select
                        v-model="filterObj.orderStatus"
                        :key="filterObj"
                        filterable
                        placeholder="退款状态"
                        clearable
                    >
                        <Option value="all" key="all">全部</Option>
                        <Option
                            v-for="item in orderStatus"
                            :value="item.dictValue"
                            :key="item.dictValue"
                            >{{ item.dictName }}</Option
                        >
                    </Select>
                </div>
                <div class="filter-btn-group">
                    <Button
                        type="primary"
                        style="width: 51px; height: 35px"
                        @click="handleSearch"
                        icon="ios-search"
                    ></Button>
                    <Button
                        style="width: 51px; height: 35px"
                        @click="handleReset"
                    >
                        <i
                            class="iconfont icon-gengxin"
                            style="font-size: 14px; margin-right: 5px"
                        ></i>
                    </Button>
                </div>
            </div>
        </header>
        <div style="padding: 10px 0 20px">
            <Table
                class="m-table"
                stripe
                :columns="columns"
                :data="dataSource"
                :loading="loading"
                @on-change="onChange"
            ></Table>
        </div>
        <div class="page">
            <Page
                :total="count"
                :current="pageNo"
                :page-size="pageSize"
                show-total
                show-elevator
                @on-change="onChange"
            />
        </div>
    </div>
</template>

<script>
import api from "@/api/commonApi";
import tablePlus from "@/components/tablePlus";
import Utils from "@/utils";
import { DatePicker } from "view-design";
const filterObj = {
    orderNumber: null,
    time: null,
    memberName: null,
    memberTelephone: null,
    businessSources: null, //'all'
    orderStatus: null, //'all'
};
export default {
    components: {
        tablePlus,
        DatePicker,
    },
    data() {
        const that = this;
        return {
            businessSourcesList: [
                { dictName: "咨询", dictValue: 0 },
                { dictName: "问诊", dictValue: 1 },
                { dictName: "复诊续方", dictValue: 2 },
                // {dictName: '续方', dictValue: 3},
                { dictName: "用药咨询", dictValue: 4 },
                { dictName: "购药", dictValue: 5 },
                { dictName: "预约挂号", dictValue: 6 },
                { dictName: "家医签约", dictValue: 7 },
                { dictName: "远程门诊", dictValue: 8 },
                // {dictName: '直播', dictValue: 9},
                // {dictName: '点播', dictValue: 10},
                // {dictName: '诊间缴费（线上）', dictValue: 11},
                // {dictName: '充值', dictValue: 12},
                // {dictName: '住院押金缴费', dictValue: 13},
                // {dictName: '院后随访', dictValue: 14},
                // {dictName: '外延处方', dictValue: 15},
                { dictName: "远程会诊", dictValue: 16 },
                // {dictName: '病历复印', dictValue: 17},
                // {dictName: '检查检验预约', dictValue: 18},
                { dictName: "检查预约", dictValue: 19 },
                { dictName: "检验预约", dictValue: 20 },
                { dictName: "体检预约", dictValue: 21 },
                { dictName: "手术预约", dictValue: 23 },
                { dictName: "互联网缴费", dictValue: 22 },
            ],
            orderStatus: [
                { dictName: "申请中", dictValue: 0 },
                { dictName: "已退款", dictValue: 1 },
                { dictName: "拒绝退款", dictValue: 2 },
                { dictName: "退款中", dictValue: 3 },
                { dictName: "同意退款", dictValue: 4 },
            ],
            filterObj: { ...filterObj },
            dataSource: [],
            pageNo: 1,
            pageSize: 10,
            count: 0,
            columns: [
                {
                    type: "sum",
                    width: 80,
                    align: "center",
                    title: "排序",
                    render: (h, params) => {
                        let sum =
                            (this.pageNo - 1) * this.pageSize +
                            params.index +
                            1;
                        return h("span", sum);
                    },
                },
                {
                    key: "orderNumber",
                    title: "订单号",
                    width: 260,
                    align: "center",
                },
                { key: "memberName", title: "用户", align: "center" },
                { key: "memberTelephone", title: "手机号", align: "center" },
                {
                    key: "businessSources",
                    title: "订单类型",
                    align: "center",
                    render(h, params) {
                        return (
                            that.businessSourcesList.filter(
                                (item) =>
                                    item.dictValue == params.row.businessSources
                            )[0] || {}
                        ).dictName;
                    },
                },
                { key: "amt", title: "订单金额", align: "center" },
                { key: "createTime", title: "申请时间", align: "center" },
                {
                    key: "orderStatus",
                    title: "状态",
                    align: "center",
                    render(h, params) {
                        return (
                            that.orderStatus.filter(
                                (item) =>
                                    item.dictValue == params.row.orderStatus
                            )[0] || {}
                        ).dictName;
                    },
                },
                {
                    key: "_operate",
                    title: "设置",
                    align: "center",
                    render(h, params) {
                        const {
                            businessSources,
                            id,
                            serviceId,
                            orderNumber,
                            businessId,
                            orderStatus,
                        } = params.row;
                        return h(
                            "span",
                            {
                                props: {
                                    type: "primary",
                                },
                                style: {
                                    color: "#5362e1",
                                    margin: "0px 6px",
                                },
                                on: {
                                    click() {
                                        if (
                                            [0, 1, 2, 3, 4].indexOf(
                                                businessSources
                                            ) > -1
                                        ) {
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_1",
                                                {
                                                    id,
                                                    orderNumber,
                                                    businessSources,
                                                }
                                            );
                                        } else if (
                                            [5].indexOf(businessSources) > -1
                                        ) {
                                            localStorage.setItem(
                                                "orderStatus",
                                                params.row.orderStatus
                                            );
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_3",
                                                { id, businessId }
                                            );
                                        } else if (
                                            [6].indexOf(businessSources) > -1
                                        ) {
                                            if (!businessId)
                                                return that.$Message.error(
                                                    "数据缺少必要信息请联系管理员"
                                                );
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_4",
                                                { id, businessId }
                                            );
                                        } else if (
                                            [7].indexOf(businessSources) > -1
                                        ) {
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_2",
                                                { id, businessId }
                                            );
                                        } else if (
                                            [8].indexOf(businessSources) > -1
                                        ) {
                                            if (!businessId)
                                                return that.$Message.error(
                                                    "数据缺少必要信息请联系管理员"
                                                );
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_8",
                                                { id, businessId }
                                            );
                                        } else if (
                                            [16].indexOf(businessSources) > -1
                                        ) {
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_16",
                                                { id, businessId }
                                            );
                                        } else if (
                                            [19, 20, 21, 23].indexOf(
                                                businessSources
                                            ) > -1
                                        ) {
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_19",
                                                { id }
                                            );
                                        } else if (
                                            [22].indexOf(businessSources) > -1
                                        ) {
                                            that.jumpTo(
                                                "/index/orders/feedBackMgt/detail_22",
                                                { id }
                                            );
                                        }
                                    },
                                },
                            },
                            params.row.orderStatus == 0 ? "审核" : "详情"
                        );
                    },
                },
            ],
            loading: false,
        };
    },
    created() {
        let breadList = [
            { path: "/index", title: "首页" },
            {
                path: "",
                title: "订单管理",
            },
            {
                path: "/index/operation/orders/feedBackMgt/list",
                title: "退费审批管理",
            },
        ];
        this.$emit("changeBreadList", breadList);
        const { filterObj } = this.$route.query;
        filterObj &&
            (this.filterObj = JSON.parse(decodeURIComponent(filterObj)));

        if(this.$store.state.resourceUrl == 'gphealth'){
            this.businessSourcesList = this.businessSourcesList.filter(col => col.dictName !== '问诊' && col.dictName !== '购药' && col.dictName !== '复诊续方');
        }
    },
    mounted() {
        this.refundPage(1);
    },
    methods: {
        handleSearch() {
            this.pageNo = 1;
            this.refundPage(1);
        },
        handleReset() {
            this.filterObj = { ...filterObj };
            this.pageNo = 1;
            this.refundPage(1);
        },
        onChange(index) {
            this.pageNo = index;
            this.refundPage(index);
        },
        jumpTo(path, query = {}) {
            this.$router.push({
                path,
                query: Object.assign(
                    {
                        filterObj: encodeURIComponent(
                            JSON.stringify(this.filterObj)
                        ),
                    },
                    query
                ),
            });
        },
        //用户退款申请分页列表
        refundPage(val) {
            const {
                orderNumber,
                createTime_GOE,
                createTime_LOE,
                memberName,
                memberTelephone,
                businessSources,
                orderStatus,
            } = this.filterObj;
            const reqBody = {
                pageNo: val,
                pageSize: 10,
                orderNumber: orderNumber,
                startTime: this.filterObj.time
                    ? Utils.getNowDateBySpecialFormat(this.filterObj.time[0])
                    : null,
                endTime: this.filterObj.time
                    ? Utils.getNowDateBySpecialFormat(this.filterObj.time[1])
                    : null,
                memberName: memberName,
                memberTelephone: memberTelephone,
                businessSources,
                orderStatus,
            };
            reqBody.businessSources === "all" && delete reqBody.businessSources;
            reqBody.orderStatus === "all" && delete reqBody.orderStatus;
            // this.loading = true;
            this.$axios.post(api.findWxRefundPage, reqBody).then((res) => {
                if (res.data.code === 1) {
                    const { records, total, pageNo } = res.data.object;
                    this.count = total;
                    if (records) {
                        this.dataSource = records;
                    } else {
                        this.dataSource = [];
                        this.count = 0;
                    }
                } else {
                    this.$Message.error(res.data.message);
                }
                // this.loading = false;
            });
        },
    },
};
</script>

<style scoped lang="less">
.page-wrapper {
    padding: 10px;
    width: 100%;
    background: #ffffff;
    box-sizing: border-box;
    .m-table {
        margin: 10px 0;
    }
    .filter-part {
        display: flex;
        flex-wrap: wrap;
        .filter-item {
            display: flex;
            margin: 10px 10px 10px 0;
            label {
                white-space: nowrap;
                line-height: 32px;
                padding-left: 5px;
                text-align: right;
            }
            .input {
                width: 220px;
            }
            .select {
                width: 70px;
            }
        }
        .filter-btn-group {
            margin: 10px 10px 10px 0;
            flex: 0 0 auto;
        }
    }
    .page {
        width: 100%;
        margin-bottom: 20px;
        text-align: center;
    }
}
</style>
